package com.itheima.web;

import com.itheima.domain.Student;
import com.itheima.servlet.StudentServlet;
import com.itheima.servlet.StudentServletImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UpdateStudentServlet")
public class UpdateStudentServlet extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
        }

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //1.获取需要修改的学生id
            String id = request.getParameter("id");
            //2.调用service查询最新学生信息用作回显
            StudentServlet studentService = new StudentServletImpl();
            Student student = studentService.findByid(Integer.parseInt(id));
            //3.跳转到修改页面
            request.setAttribute("student",student);
            request.getRequestDispatcher("update.jsp").forward(request,response);
        }
}
